package com.yowasa.xiuxian.util;

import com.yowasa.xiuxian.engine.battle.strategy.DefendStrategy;
import org.springframework.core.annotation.Order;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class OrderUtil {

    public static Integer getOrderNum(Object e) {
        Order annotation = e.getClass().getAnnotation(Order.class);
        if (annotation == null) {
            return Integer.MIN_VALUE;
        }
        return annotation.value();
    }

    public static void sortByOrder(List list) {
        list.sort(Comparator.comparingInt(OrderUtil::getOrderNum));
    }

    public static void sortByOrderDesc(List list) {
        list.sort(Comparator.comparingInt(OrderUtil::getOrderNum));
        Collections.reverse(list);
    }
}
